<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>

    <div class="layui-form layuimini-form">
        <form class="layui-form" action="" lay-filter="example">
        <div style="display: none" class="layui-form-item">
            <label class="layui-form-label required">楼栋id</label>
            <div class="layui-input-inline">
                <input  type="number" name="bid" disabled=""  value="" class="layui-input">
                <tip>id自动添加。</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">所属小区</label>
            <div class="layui-input-inline">
                <select name="hid" lay-verify="" id="hname">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">楼栋编号</label>
            <div class="layui-input-inline">
                <input type="text" name="bnumber" lay-verify="required" lay-reqtext="楼栋编号不能为空" value="" class="layui-input">
            </div>
        </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">楼栋名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="bname" lay-verify="required" lay-reqtext="楼栋名称不能为空" value="" class="layui-input">
                </div>
            </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-inline">
                <input type="text" name="bdescribe"  value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
                    <label class="layui-form-label required">创建时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="bhiredate" class="layui-input" autocomplete="off" id="time1" placeholder="yyyy-MM-dd">
                    </div>
                </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                    </div>
                </div>
        </form>
    </div>
                <script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','laydate','upload'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
            element = layui.element,
            laydate = layui.laydate,
            upload = layui.upload;
//渲染时间组件
        laydate.render({
            elem: '#time1'
        });

        //发送ajax异步请求，获取所有的小区信息
        $.post({
            url:'/housing?methodName=all&page=1&limit=1000',
            success:function(res){
                var housings = res.data;
                if(res.code == 0){
                    $.each(housings,function(index,housing){
                        $("#hname").append(`<option value="${housing.hid}">${housing.hname}</option>`)
                    })
                }else{
                    $("#hname").append(`<option>获取数据失败</option>`)
                }
                //从新渲染表单
                form.render();
            }
        })


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.post({
                url:'/building?methodName=add',
                data:{
                    building:JSON.stringify(data.field)
                },
                success:function(){

                },

            })
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
            return false;
        });


        });


</script>
</body>
</html>